<template>
	<view class="container">
		<view style="text-align: center;margin-top: 20%;">
			<text style="font-size: 170%;">虞兮贸易PDA</text>
		</view>
		<view style="margin-top: 10%;">
			<uni-section class="mb-10" title="仓库名称">
				<template v-slot:right>
					<view style="width: 550rpx;">
						<uni-data-select v-model="warehouseNo" :localdata="range" @change="selectFun"></uni-data-select>
					</view>
				</template>
			</uni-section>
		</view>
		<view>
			<uni-section class="mb-10" title="账号">
				<template v-slot:right>
					<view style="width: 550rpx;">
						<uni-easyinput v-model="account" placeholder="请输入内容"></uni-easyinput>
					</view>
				</template>
			</uni-section>
		</view>
		<view>
			<uni-section class="mb-10" title="密码">
				<template v-slot:right>
					<view style="width: 550rpx;">
						<uni-easyinput v-model="password" placeholder="请输入内容"></uni-easyinput>
					</view>
				</template>
			</uni-section>
		</view>
		<view style="text-align: center;margin-top: 10%;">
			<button plain="true" size="default" @click="loginFun">登录</button>
		</view>

	</view>

</template>

<script>
	import {
		stockList,
		login
	} from '../config/api.js';
	export default {
		data() {
			return {
				warehouseNo: null,
				stockName: null,
				account: null,
				password: null,
				range: []
			}
		},
		onLoad() {
			this.stockListFun()
		},
		methods: {
			selectFun(e) {
				console.log(e)
				for (var i = 0; i < this.range.length; i++) {
					if (this.range[i].value == e) {
						this.stockName = this.range[i].text
					}
				}
			},
			stockListFun() {
				let that = this;
				// get请求
				stockList({
					custom: {},
					params: {}
				}).then((e) => {
					console.log(e)
					if (e.code == 200) {
						for (var i = 0; i < e.data.length; i++) {
							if(e.data[i].stockNo=="025"||e.data[i].stockNo=="011"||e.data[i].stockNo=="048"){
								that.range.push({
									value: e.data[i].stockNo,
									text: e.data[i].stockName
								})
							}
						}
					}
				}).catch((e) => {
					console.log(e)
				})
			},
			loginFun() {
				if (this.stockName == null || this.account == null || this.password == null || this.stockName == "" || this
					.account == "" || this.password == "") {
					uni.showToast({
						title: "请输入完整"
					})
				}
				// get请求
				login({
					custom: {},
					params: {
						warehouseNo: this.warehouseNo,
						stockName: this.stockName,
						account: this.account,
						passWord: this.password,
					}
				}).then((e) => {
					if (e.code == 200 && e.data != null) {
						uni.setStorageSync("userInfoByPDA", e.data)
						if (e.data.identy == 1) {
							uni.reLaunch({
								url: "/pages/gongchang/index",
								success() {
									uni.setTabBarItem({
										index: 1,
										visible: false
									})
									uni.setTabBarItem({
										index: 0,
										visible: true
									})
								}
							})
						} else {
							uni.reLaunch({
								url: "/pages/cangku/cangku",
								success() {
									uni.setTabBarItem({
										index: 1,
										visible: true
									})
									uni.setTabBarItem({
										index: 0,
										visible: false
									})
								}
							})
						}
					}
				}).catch((e) => {
					console.log(e)
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: white;
	}
 
</style>